<?php
class CConsultUtil
{	
	//bitrix/modules/main/tools.php
	function DelDuplicateSort(&$arSort)
	{
		if (is_array($arSort) && count($arSort)>0)
		{
			$arSort2 = array();
			foreach($arSort as $val)
			{
				$arSort1 = explode(" ", trim($val));
				$order = array_pop($arSort1);
				$order_ = strtoupper(trim($order));
				if (!($order_=="DESC" || $order_=="ASC"))
				{
					$arSort1[] = $order;
					$order_ = "";
				}
				$by = implode(" ", $arSort1);
				if(strlen($by)>0 && !array_key_exists($by, $arSort2))
					$arSort2[$by] = $order_;
			}
			$arSort = array();
			foreach($arSort2 as $by=>$order)
				$arSort[] = $by." ".$order;
		}
	}
	//
	function GetFilterOperation($key)
	{
		$strNegative = "N";
		if (substr($key, 0, 1)=="!")
		{
			$key = substr($key, 1);
			$strNegative = "Y";
		}

		if (substr($key, 0, 2)==">=")
		{
			$key = substr($key, 2);
			$strOperation = ">=";
		}
		elseif (substr($key, 0, 1)==">")
		{
			$key = substr($key, 1);
			$strOperation = ">";
		}
		elseif (substr($key, 0, 2)=="<=")
		{
			$key = substr($key, 2);
			$strOperation = "<=";
		}
		elseif (substr($key, 0, 1)=="<")
		{
			$key = substr($key, 1);
			$strOperation = "<";
		}
		elseif (substr($key, 0, 1)=="@")
		{
			$key = substr($key, 1);
			$strOperation = "IN";
		}
		elseif (substr($key, 0, 1)=="%")
		{
			$key = substr($key, 1);
			$strOperation = "LIKE";
		}
		else
		{
			$strOperation = "=";
		}

		return array("FIELD"=>$key, "NEGATIVE"=>$strNegative, "OPERATION"=>$strOperation);
	}
}
?>